package com.common.util;

import java.util.List;

public class Pager {
    
    public boolean isFirst;
    public boolean isLast;
    public int pageNo = 1;
    public int pageSize = 20;
    public int totalCount;
    
    
    public boolean isLastPage() {
        return isLast;
    }
    
    /**
     * 判断当前是否为第一页
     *
     * @return
     */
    public boolean isFirstPage() {
        return isFirst;
    }
    
    /**
     * 获取下一页码
     *
     * @return
     */
    public int getNextPageNo() {
        return pageNo + 1;
    }
    
    /**
     * 判断是否为空页码
     *
     * @return
     */
    public boolean isPageEmpty() {
        if (totalCount == 0) {
            return true;
        }
        return false;
    }
    
    public void computer(List datas) {
        if (datas == null || datas.isEmpty()) {
            isLast = true;
            if (pageNo <= 1) {
                pageNo = 1;
                isFirst = true;
            } else {
                pageNo--;
                isFirst = false;
            }
        } else {
            totalCount += datas.size();
            if (pageSize > datas.size()) {
                isLast = true;
            } else {
                isLast = false;
            }
            if (pageNo == 1) {
                isFirst = true;
            } else {
                isFirst = false;
            }
        }
        
    }
    
    public boolean hasData() {
        if (totalCount > 0) {
            return true;
        }
        return false;
    }
}
